package com.yuyou.train.admin.controller;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yuyou.train.admin.service.ICommKeyConfigService;
import com.yuyou.train.admin.service.ICommSmsVerCodeService;
import com.yuyou.train.service.api.admin.entity.CommKeyConfig;
import com.yuyou.train.service.api.admin.entity.CommSmsVerCode;
import com.yuyou.train.util.bean.ReturnResult;

@Validated
@RestController
@RequestMapping(value="/api/sms")
public class CommSmsVerCodeController  {

	@Autowired
	private ICommSmsVerCodeService commSmsVerCodeService;
	
	@Autowired
	private ICommKeyConfigService commKeyConfigService;
	
	@Value("${sms.key}")
	private String key;
	
	
	@RequestMapping(value="/selectTestSms",method=RequestMethod.GET)
	public ReturnResult<CommSmsVerCode> selectTestSms(
			@NotNull(message="mobile不能为空") String mobile,
			@NotNull(message="key不能为空") String key){	
		CommSmsVerCode commSmsVerCode=null;
		if(key.equals(this.key)){			
			CommKeyConfig sms_list = commKeyConfigService.selectByDataKey("sms_list");
			if(sms_list != null && sms_list.getDataValue().equals("1")){
				commSmsVerCode=commSmsVerCodeService.selectLastByMobile(mobile);
			}
		}
		return ReturnResult.success(commSmsVerCode);
	}
	



}
